//
//  XMCSConfiguration.m
//  XMJJ_zml
//
//  Created by 杨何华 on 2025/5/23.
//

#import "XMCSConfiguration.h"
#import "XMCSPopularCitiesModel.h"

@implementation XMCSConfiguration

- (instancetype)init {
    self = [super init];
    if (self) {
        _isPinyinSearch = YES;
        _isLowercaseString = NO;
        _hidePopularCities = NO;
        _hideHistoricalRecord = NO;
        _hideAreaSwitchButton = NO;
        _searchButtonBackgroundColor = [UIColor whiteColor];
        _searchButtonTitleColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1];
        _sectionIndexColor = [UIColor colorWithRed:0/255.0f green:132/255.0f blue:255/255.0f alpha:1];
        _maxHistoricalRecordCount = 3;
        
        self.popularCitiesMutableArray = [self defealtPopularCities];
        self.popularCitiesTitle = @"热门城市";
        self.historicalRecordTitle = @"最近访问";
        
        _leftBarButtonItemImageName = @"jf_icon_navi_return";
        _searchButtonImageName = @"jf_icon_search_button";
        _searchButtonTitle = @"城市名/拼音";
        _searchControllerCancelButtonTitle = @"取消";
        _searchControllerCancelButtonTitleFont = [UIFont systemFontOfSize:14.0];
        _tableViewCellTextLabelFont = [UIFont systemFontOfSize:14.0];
        _promptInformation = @"抱歉，未找到相关位置，可尝试修改后重试";
    }
    return self;
}

#pragma mark -- Set

- (void)setPopularCitiesMutableArray:(NSMutableArray<XMCSPopularCitiesModel *> *)popularCitiesMutableArray {
    _popularCitiesMutableArray = popularCitiesMutableArray;
    _popularCitiesCellHeight = [self calculateCellHeightWithCount:popularCitiesMutableArray.count];
}

- (void)setIsPinyinSearch:(BOOL)isPinyinSearch {
    _isPinyinSearch = isPinyinSearch;
    _searchButtonTitle = isPinyinSearch ? _searchButtonTitle : @"城市名";
}

- (void)setPopularCitiesTitle:(NSString *)popularCitiesTitle {
    _popularCitiesTitle = popularCitiesTitle;
    _popularCitiesAbbreviation = popularCitiesTitle.length >= 2 ? [popularCitiesTitle substringToIndex:2] : @"*";
}

- (void)setHistoricalRecordTitle:(NSString *)historicalRecordTitle {
    _historicalRecordTitle = historicalRecordTitle;
    _historicalRecordAbbreviation = historicalRecordTitle.length >= 2 ? [historicalRecordTitle substringToIndex:2] : @"#";
}

#pragma mark -- Get

- (NSMutableArray <XMCSPopularCitiesModel *> *)defealtPopularCities {
    XMCSPopularCitiesModel *bjModel = [[XMCSPopularCitiesModel alloc] initWithName:@"北京" type:XMCSPopularCitiesTypeCity];
    XMCSPopularCitiesModel *shModel = [[XMCSPopularCitiesModel alloc] initWithName:@"上海" type:XMCSPopularCitiesTypeCity];
    XMCSPopularCitiesModel *gzModel = [[XMCSPopularCitiesModel alloc] initWithName:@"广州" type:XMCSPopularCitiesTypeCity];
    XMCSPopularCitiesModel *szModel = [[XMCSPopularCitiesModel alloc] initWithName:@"深圳" type:XMCSPopularCitiesTypeCity];
    XMCSPopularCitiesModel *hzModel = [[XMCSPopularCitiesModel alloc] initWithName:@"杭州" type:XMCSPopularCitiesTypeCity];
    return [NSMutableArray arrayWithObjects:bjModel, shModel, gzModel, szModel, hzModel, nil];
}

#pragma mark -- Action

- (CGFloat)calculateCellHeightWithCount:(NSInteger)count {
    NSInteger tempCount = count / 3;
    if ((count % 3) > 0) {
        tempCount += 1;
    }
    return tempCount * 48;
}

@end
